package com.shop2cn.iapi.cdfgeteway.service;

import org.json.JSONObject;

import com.shop2cn.iapi.cdfgeteway.resp.PointsVo;

import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.utils.EnvSetup;

/**
 * 取消订单Call FreeMaker Template自动生成代码
 */
public class GetUserPointsCall extends YmatouBaseCall {
	private static String opurl = "points/getUserPoints";

	public GetUserPointsCall() {
//		super(EnvSetup.getSystemUrl("operate2_iapi"), opurl, "POST", "JSON");
		super(EnvSetup.getSystemUrl("cdfgeteway_iapi"), opurl, "POST", "JSON");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept",
				"text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	/**
	 * 获取Code
	 * 
	 * @return
	 */
	public String getCode() {
		String Code = null;
		try {
			Code = new JSONObject(getReturnData()).optString("code");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Code;
	}

	/**
	 * 获取BCode
	 * 
	 * @return
	 */
	public String getBCode() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).optString("bcode");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Msg
	 * 
	 * @return
	 */
	public String getMsg() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).optString("msg");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	
	public PointsVo getPointsVo()
			throws Exception {
		
		Object result = new JSONObject(getReturnData()).get("pointsVo");
		
		if (result.toString().equalsIgnoreCase("null"))
			return null;
		else
			return (PointsVo) FormatUtil.GSONToObject(
					new JSONObject(getReturnData()).getJSONObject("pointsVo")
							.toString(), PointsVo.class);
	}
}
